package com.jstower.modules.sample.controller;

import com.jstower.common.controller.AppResponse;
import com.jstower.common.controller.BaseController;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description: 一个demo
 * Author: chenshuai
 * Project: js-webapp
 * Version: V1.0
 * Create Date: 16/3/1
 * Controller上标注了@RestController，这样相当于Controller的所有方法都标注了@ResponseBody
 * 如果这不是一个接口，那就使用@Controller注解
 */
//@Scope("prototype")
@RequestMapping(value = "/sample")
@RestController
//@Controller
public class SampleController extends BaseController {

    @RequestMapping(value = "/detail/{userId}", method = RequestMethod.GET)
    public AppResponse detail(@PathVariable String userId, Model model) {
        appResponse = new AppResponse();
        appResponse.setData(userId);
        appResponse.setSuccess(true);
        return appResponse;
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public AppResponse listSample() {
        appResponse = new AppResponse();
        System.out.println("******");
        return appResponse;
    }

    @RequestMapping(value = "/view/{userId}")
    public String view(@PathVariable String userId, ModelMap model) {
        model.put("userId", userId);
//        return "redirect:/index.jsp";
        return "modules/sample/sample_list";
    }
}
